package com.lut.edu.apm.payCenter.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 订单详情
 *
 * @author Zhao Suzhen
 * @date `2024/4/10`
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "t_order_detail")
public class OrderDetail {
    @TableId(type = IdType.AUTO, value = "od_id")
    private int odId;
    @TableField(value = "user_id")
    private String userId;
    @TableField(value = "order_no")
    private String orderNo;
    @TableField(value = "product_id")
    private String productId;
    @TableField(value = "product_name")
    private String productName;
    @TableField(value = "number")
    private int number;
    @TableField(value = "price_product")
    private long priceProduct;
    @TableField(value = "preferential_prices")
    private long preferentialPrices;
    @TableField(value = "total_fee")
    private long totalFee;

    public List<OrderDetail> init(List<Map<String, Object>> input) {
//    public OrderDetail(String barcode, int count, Double discountPrice, String name, Double price) {
        List<OrderDetail> result = new ArrayList<>();
        for (Map<String, Object> item : input) {
            String barcode = (String) item.get("barcode");
            int count = (int) item.get("count");
            Double discountPrice = Double.parseDouble(item.get("discountPrice").toString());
            String name = (String) item.get("name");
            Double price = Double.parseDouble(item.get("price").toString());
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.productId = barcode;
            orderDetail.number = count;
            orderDetail.preferentialPrices = Math.round(discountPrice * 100);
            orderDetail.productName = name;
            orderDetail.priceProduct = Math.round(price * 100);
            orderDetail.totalFee = orderDetail.priceProduct - orderDetail.preferentialPrices;
            result.add(orderDetail);
        }
        return result;
    }
}
